<template>
    <div>
        <el-breadcrumb separator="/" style="margin-bottom:20px;">
            <el-breadcrumb-item :to="{ path: '/' }">
                <i class="el-icon-setting" style="margin-right:4px;"></i>首页</el-breadcrumb-item>
            <el-breadcrumb-item>集团酒店切换</el-breadcrumb-item>
        </el-breadcrumb>
        <el-form ref="form" :model="form" label-width="150px">
            <el-form-item label="集团选择">
                <el-cascader expand-trigger="hover" :options="selectCity" v-model="selectedOptions" @change="handleCity"></el-cascader>
            </el-form-item>
        </el-form>
        <el-form ref="form" :model="form" label-width="150px">
            <el-form-item label="集团酒店首页链接">
                <el-input v-model="groupUrl" style="width:500px"></el-input>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
export default {
    data() {
        return {
            selectCity: [{
                value: 0,
                label: ""
            }],
            selectedOptions: [],
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            groupUrl: ""
        }
    },
    mounted() {

        //当前集团id
        this.selectedOptions[0] = this.$store.state.grogshop.hotelId;

        // this.indexUrl(this.$store.state.grogshop.hotelId);

        //设置当前集团name
        if (this.$store.state.grogshop.hotelId === this.$store.state.login.belong_gs) {
            this.$store.commit("grogshopMessage", this.$store.state.login.belong_name);
        }

        //集团酒店获取
        this.$http.get(this.ajaxUrl() + "/index/mainGrogshop?type=1").then((response) => {
            this.selectCity = [];
            for (let i = 0; i < response.data.length; i++) {
                this.selectCity.push({
                    value: response.data[i].hotel_id,
                    label: response.data[i].hotel_name,
                    id: response.data[i].app_id
                })
            }
        })
    },
    methods: {
        onSubmit() {

        },
        handleCity(value) {

            this.indexUrl(value[0]);

            this.$store.commit("mianGrogshopID", value[0]);

            //多级下拉列表组件只返回了集团id，取不到集团name。这里通过循环匹配集团id，取集团name
            let city = this.selectCity;
            for (let i = 0; i < city.length; i++) {
                if (city[i].value === value[0]) {
                    this.$store.commit("grogshopMessage", city[i].label, city[i].id);
                }
            }
        },
        indexUrl(id) {
            // this.groupUrl = `http://hotel.sindon.cn/nest/Tool/${this.$store.state.grogshop.appId}/index.html?mainId=${id}`;
            this.groupUrl = 'http://hotel.sindon.cn/nest/Tool/test/index.html?mainId=' + id;
        }
    }
}
</script>


